package org.apache.catalina.util;
public final class StringParser {
    public StringParser() {
        this(null);
    }

    public StringParser(String string) {
        super();
        setString(string);
    }

    private char chars[] = null;

    private int index = 0;

    private int length = 0;

    private String string = null;

    public int getIndex() {
        return (this.index);
    }

    public int getLength() {
        return (this.length);
    }

    public String getString() {
        return (this.string);
    }

    public void setString(String string) {
        this.string = string;
        if (string != null) {
            this.length = string.length();
            chars = this.string.toCharArray();
        } else {
            this.length = 0;
            chars = new char[0];
        }
        reset();
    }

    public void advance() {
        if (index < length)
            index++;
    }

    public String extract(int start) {
        if ((start < 0) || (start >= length))
            return ("");
        else
            return (string.substring(start));
    }

    public String extract(int start, int end) {
        if ((start < 0) || (start >= end) || (end > length))
            return ("");
        else
            return (string.substring(start, end));
    }

    public int findChar(char ch) {
        while ((index < length) && (ch != chars[index]))
            index++;
        return (index);
    }

    public int findText() {
        while ((index < length) && isWhite(chars[index]))
            index++;
        return (index);
    }

    public int findWhite() {
        while ((index < length) && !isWhite(chars[index]))
            index++;
        return (index);
    }

    public void reset() {
        index = 0;
    }

    public int skipChar(char ch) {
        while ((index < length) && (ch == chars[index]))
            index++;
        return (index);
    }

    public int skipText() {
        while ((index < length) && !isWhite(chars[index]))
            index++;
        return (index);
    }

    public int skipWhite() {
        while ((index < length) && isWhite(chars[index]))
            index++;
        return (index);
    }

    protected boolean isWhite(char ch) {
        if ((ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n'))
            return (true);
        else
            return (false);
    }
}